const { usernameIsExist_3, platformRegister_3, storeRegister_3, login1, login2 } = require("../dao/usersDao");

// 验证账号是否已存在
module.exports.usernameIsExist_2 = async function(data){
    let result = await usernameIsExist_3(data);
    console.log(result.length);
    if(result.length){
        return true;
    }
    return false;
}

// 新用户注册
module.exports.register_2 = async function (data) {
    let { position } = data;
    if (position == "门店管理员") {
        let result = await storeRegister_3(data);
        if (result._id) {
            return true
        }
        return false
    } else {
        let result = await platformRegister_3(data);
        if (result._id) {
            return true
        }
        return false
    }
}
module.exports.login = async function (data) {
    let { position } = data;
    if (position == "门店管理员") {
        let result = await login1(data);
        if (result.length > 0) {
            return { users: result[0], flag: true }
        } else {
            return { flag: false }
        }
    } else {
        let result = await login2(data);
        if (result.length > 0) {
            return { users: result[0], flag: true }
        } else {
            return { flag: false }
        }
    }





}